package cn.arikeky.controller;


import cn.arikeky.result.JsonResult;
import cn.arikeky.result.PageList;
import cn.arikeky.service.IMoveUserService;
import com.baomidou.mybatisplus.plugins.Page;
import cn.arikeky.domain.MoveUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.arikeky.query.MoveUserQuery;

@RestController
@RequestMapping("/moveUser")
public class MoveUserController {

    @Autowired
    public IMoveUserService moveUserService;




    /**
    * 保存和修改公用的
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JsonResult saveOrUpdate(@RequestBody MoveUser moveUser){
        if(moveUser.getId()!=null){
            moveUserService.updateById(moveUser);
        }else{
            moveUserService.insert(moveUser);
        }
        return JsonResult.success();
    }

    /**
    * 删除对象
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JsonResult delete(@PathVariable("id") Long id){
        moveUserService.deleteById(id);
        return JsonResult.success();
    }

    /**
   * 获取对象
   */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JsonResult get(@PathVariable("id")Long id){
        return JsonResult.success(moveUserService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResult list(){
        return JsonResult.success(moveUserService.selectList(null));
    }


    /**
    * 带条件分页查询数据
    */
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JsonResult page(@RequestBody MoveUserQuery query){
        Page<MoveUser> page = new Page<MoveUser>(query.getPage(),query.getRows());
        page = moveUserService.selectPage(page);
        return JsonResult.success(new PageList<MoveUser>(page.getTotal(),page.getRecords()));
    }

    /**
     * 查询所有对象
     */
    @RequestMapping(value = "/{userId}/{movieId}",method = RequestMethod.GET)
    public JsonResult watch(@PathVariable("userId")Long userId, @PathVariable("movieId")Long movieId){
        return moveUserService.watch(userId, movieId);
    }

}
